package com.hubu.parking.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hubu.parking.common.BaseResponse;
import com.hubu.parking.common.DeleteRequest;
import com.hubu.parking.common.ResultUtils;
import com.hubu.parking.entity.park.Notice;
import com.hubu.parking.model.dto.park.PageListNoticeRequest;
import com.hubu.parking.model.vo.NoticeVo;
import com.hubu.parking.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 实际停车记录接口
 */
@RestController
@RequestMapping("/notice")
@Slf4j
public class NoticeController {
    @Resource
    private NoticeService noticeService;

    /**
     * 查询
     *
     * @return
     */
    @PostMapping("/list")
    public BaseResponse<Page<NoticeVo>> listNotice(@RequestBody PageListNoticeRequest pageRequest) {
        return ResultUtils.success(noticeService.pageListNoticeRecord(pageRequest));
    }

    /**
     * 查询
     *
     * @return
     */
    @PostMapping("/listNoPage")
    public BaseResponse<List<Notice>> listNoticeNoPage() {
        return ResultUtils.success(noticeService.listNoticeNoPage());
    }

    /**
     * 新增/修改公告
     *
     * @param notice 公告
     * @return
     */
    @PostMapping("saveOrUpdate")
    public BaseResponse<Boolean> add(@RequestBody Notice notice) {
        boolean save = noticeService.saveOrUpdate(notice);
        return ResultUtils.success(save);
    }

    /**
     * 删除
     *
     * @param deleteRequest
     * @return
     */
    @PostMapping("delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest deleteRequest) {
        Integer deleteId = deleteRequest.getId();
        boolean b = noticeService.removeById(deleteId);
        return ResultUtils.success(b);
    }

}
